/**
 * 
 */
package com.googlecode.xcarve.router;

import java.util.List;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

import com.googlecode.xcarve.object.RPCRequest;
import com.googlecode.xcarve.transport.Client;

/**
 * @author xinyun.d
 * 2014年10月26日
 */
public class RandomRouter implements Router{
	static final Logger logger = LoggerFactory.getLogger(RandomRouter.class);

	/* (non-Javadoc)
	 * @see com.dove.transport.cluster.Router#select(java.util.List, java.lang.String)
	 */
	@Override
	public Client select(List<? extends Client> list, RPCRequest request) {
		if(CollectionUtils.isEmpty(list)){
			return null;
		}
		int random = new Random().nextInt(list.size());
		return list.get(random);
	}
	
	public void update(final List<? extends Client> list,String service){
		
	}
}
